const app = getApp();
Page({
  data:{
    title:'相关条款',
    inputB:'',
    inputB2:''
  },
  onShow:function(){
    this.getAgreeMent();
  },
  // 条款
  getAgreeMent: function () {
    this.setData({
      title: app.globalData.agreementTitle
    })
  },
  // 得到支付密码
  getpwd: function (e) {
    if(e.detail.value.length == 6){
      this.setData({
        pwd: e.detail.value
      })
    }
  },
  getpwd2: function (e) {
    if(e.detail.value.length == 6){
      this.setData({
        surepwd: e.detail.value
      })
    }
  },
  //是否同意
  checkboxChange:function(e){
    if (e.detail.value.length == 0) {
      this.setData({
        check:0  //未选
      })
    }
    else {
      this.setData({
        check: 1  //已选
      })
    }
    // console.log(this.data.check)
  },
  //下一步
  formSubmit: function (e) {
    const _this = this;
    this.setData({
      pwd: _this.data.pwd,
      surepwd: _this.data.surepwd
    })
    if (this.data.pwd != '' || this.data.surepwd != ''){
      if (this.data.pwd === this.data.surepwd) {
        // if (this.data.check == 1) {
          wx.request({
            url: app.globalData.path + 'services/app/applets/FirstSetPayPassword',
            data: {
              payPassword: _this.data.pwd
            },
            method: 'POST',
            header: {
              'content-type': 'application/json', // 默认值
              'Authorization': 'Bearer ' + app.globalData.authorization
            },
            success: function (res) {
              console.log(res.data)
              if (res.data.success) {
                wx.switchTab({
                  url: '../index/index'
                })
              } else {
                wx.showToast({
                  title: res.data.error.message,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        // } else {
        //   wx.showModal({
        //     content: '未同意协议',
        //     showCancel: false,
        //     success: function (res) {
        //       if (res.confirm) {
        //         // console.log('用户点击确定')
        //       }
        //     }
        //   });
        // }
      } else {
        wx.showModal({
          content: '两次密码不同',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              // console.log('用户点击确定')
            }
          }
        });
      }
    }else{
      wx.showModal({
        content: '密码为空',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            // console.log('用户点击确定')
          }
        }
      });
    }
  },
  // 协议
  agreeMent:function(){
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  }
})